/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import DAO.ChuDeDAO;
import DAO.TinTucDAO;
import DAO.WebsiteDAO;
import DAO.XpathDAO;
import DTO.ChuDeDTO;
import DTO.TinTucDTO;
import DTO.WebsiteDTO;
import DTO.XpathDTO;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author QuangHau
 */
public class Manager extends javax.swing.JDialog {

    public boolean isReset = false;
    /**
     * Creates new form Manager
     */
    public Manager(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        createJTableWebsite();
    }

    private boolean createJTableWebsite() {
        DefaultTableModel model = (DefaultTableModel) tbWebsite.getModel();
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        ArrayList<WebsiteDTO> arr = WebsiteDAO.SelectWebsite();
        if (arr != null && arr.size() > 0) {
            for (int i = 0; i < arr.size(); i++) {
                Vector Row = new Vector();
                Row.addElement(arr.get(i).getMaWebsite());
                Row.addElement(arr.get(i).getTenWebsite());
                model.addRow(Row);
            }
            tbWebsite.setModel(model);
            tbWebsite.setRowSelectionInterval(0, 0);
            btnXoaWebsite.setEnabled(true);
            btnCapNhatWebsite.setEnabled(true);
            CreateJTablesubject();
            tabPannel.setEnabledAt(1, true);
            return true;
        }
        tabPannel.setEnabledAt(1, false);
        tabPannel.setEnabledAt(2, false);
        btnXoaWebsite.setEnabled(false);
        btnCapNhatWebsite.setEnabled(false);
        return false;
    }

    private boolean CreateJTablesubject() {
        DefaultTableModel model = (DefaultTableModel) tbChuDe.getModel();
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        ArrayList<ChuDeDTO> arr = ChuDeDAO.selectAll();
        if (arr != null && arr.size() > 0) {
            SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");
            for (int i = 0; i < arr.size(); i++) {
                Vector Row = new Vector();
                Row.addElement(arr.get(i).getMaChuDe());
                Row.addElement(arr.get(i).getTenChuDe());
                Row.addElement(arr.get(i).getTenWebsite());
                String ngaybatdau = date.format(arr.get(i).getNgayBatDau());
                Row.addElement(ngaybatdau);
                Row.addElement(arr.get(i).getLinkChuDe());
                model.addRow(Row);
            }
            tbChuDe.setModel(model);
            tbChuDe.setRowSelectionInterval(0, 0);
            btnCapNhatChuDe.setEnabled(true);
            btnXoaChuDe.setEnabled(true);
            CreateJtableXpath();
            tabPannel.setEnabledAt(2, true);
            return true;
        }
        tabPannel.setEnabledAt(2, false);
        btnCapNhatChuDe.setEnabled(false);
        btnXoaChuDe.setEnabled(false);
        return false;
    }

    private boolean CreateJtableXpath() {
        DefaultTableModel model = (DefaultTableModel) tbXpath.getModel();
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        ArrayList<XpathDTO> arr = XpathDAO.selectXpathAll();
        if (arr != null && arr.size() > 0) {
            for (int i = 0; i < arr.size(); i++) {
                Vector Row = new Vector();
                Row.addElement(arr.get(i).getMaXpath());
                Row.addElement(arr.get(i).getTenXpath());
                Row.addElement(arr.get(i).getTenChuDe());
                Row.addElement(arr.get(i).getTenWebsite());
                model.addRow(Row);
            }
            tbXpath.setRowSelectionInterval(0, 0);
            tbXpath.setModel(model);
            btnCapNhatXpath.setEnabled(true);
            btnXoaXpath.setEnabled(true);
            return true;
        }
        btnCapNhatXpath.setEnabled(false);
        btnXoaXpath.setEnabled(false);
        return false;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabPannel = new javax.swing.JTabbedPane();
        tabWebsite = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbWebsite = new javax.swing.JTable();
        btnThemWebsite = new javax.swing.JButton();
        btnXoaWebsite = new javax.swing.JButton();
        btnThoatWebsite = new javax.swing.JButton();
        btnCapNhatWebsite = new javax.swing.JButton();
        TabChuDe = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbChuDe = new javax.swing.JTable();
        btnThemChuDe = new javax.swing.JButton();
        btnXoaChuDe = new javax.swing.JButton();
        btnThoatChuDe = new javax.swing.JButton();
        btnCapNhatChuDe = new javax.swing.JButton();
        tabXpath = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbXpath = new javax.swing.JTable();
        btnThemXpath = new javax.swing.JButton();
        btnXoaXpath = new javax.swing.JButton();
        btnThoatXpath = new javax.swing.JButton();
        btnCapNhatXpath = new javax.swing.JButton();
        tabDatabase = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Quản lý");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        tabPannel.setBackground(java.awt.Color.white);
        tabPannel.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabPannelStateChanged(evt);
            }
        });

        tabWebsite.setBackground(java.awt.Color.white);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Danh sách website"));

        tbWebsite.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã website ", "Tên website"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbWebsite);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        btnThemWebsite.setText("Thêm");
        btnThemWebsite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemWebsiteActionPerformed(evt);
            }
        });

        btnXoaWebsite.setText("Xóa");
        btnXoaWebsite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaWebsiteActionPerformed(evt);
            }
        });

        btnThoatWebsite.setText("Thoát");
        btnThoatWebsite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatWebsiteActionPerformed(evt);
            }
        });

        btnCapNhatWebsite.setText("Cập nhật");
        btnCapNhatWebsite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapNhatWebsiteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabWebsiteLayout = new javax.swing.GroupLayout(tabWebsite);
        tabWebsite.setLayout(tabWebsiteLayout);
        tabWebsiteLayout.setHorizontalGroup(
            tabWebsiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabWebsiteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabWebsiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(tabWebsiteLayout.createSequentialGroup()
                        .addComponent(btnThemWebsite)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCapNhatWebsite)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnXoaWebsite)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnThoatWebsite, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        tabWebsiteLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnThemWebsite, btnThoatWebsite, btnXoaWebsite});

        tabWebsiteLayout.setVerticalGroup(
            tabWebsiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabWebsiteLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(tabWebsiteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThemWebsite)
                    .addComponent(btnXoaWebsite)
                    .addComponent(btnThoatWebsite)
                    .addComponent(btnCapNhatWebsite))
                .addContainerGap())
        );

        tabPannel.addTab("Website", tabWebsite);

        TabChuDe.setBackground(java.awt.Color.white);

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Danh sách chủ đề"));

        tbChuDe.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã chủ đề ", "Tên chủ đề", "Website", "Ngày bắt đầu", "Link"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tbChuDe);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        btnThemChuDe.setText("Thêm");
        btnThemChuDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemChuDeActionPerformed(evt);
            }
        });

        btnXoaChuDe.setText("Xóa");
        btnXoaChuDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaChuDeActionPerformed(evt);
            }
        });

        btnThoatChuDe.setText("Thoát");
        btnThoatChuDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatChuDeActionPerformed(evt);
            }
        });

        btnCapNhatChuDe.setText("Cập nhật");
        btnCapNhatChuDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapNhatChuDeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout TabChuDeLayout = new javax.swing.GroupLayout(TabChuDe);
        TabChuDe.setLayout(TabChuDeLayout);
        TabChuDeLayout.setHorizontalGroup(
            TabChuDeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TabChuDeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(TabChuDeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(TabChuDeLayout.createSequentialGroup()
                        .addComponent(btnThemChuDe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCapNhatChuDe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnXoaChuDe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnThoatChuDe)))
                .addContainerGap())
        );

        TabChuDeLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCapNhatChuDe, btnThemChuDe, btnThoatChuDe, btnXoaChuDe});

        TabChuDeLayout.setVerticalGroup(
            TabChuDeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TabChuDeLayout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(TabChuDeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThemChuDe)
                    .addComponent(btnXoaChuDe)
                    .addComponent(btnThoatChuDe)
                    .addComponent(btnCapNhatChuDe))
                .addContainerGap())
        );

        tabPannel.addTab("Chủ đề", TabChuDe);

        tabXpath.setBackground(java.awt.Color.white);

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Danh sách xpath"));

        tbXpath.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã xpath", "Tên xpath", "Chủ đề", "Website"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tbXpath);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        btnThemXpath.setText("Thêm");
        btnThemXpath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemXpathActionPerformed(evt);
            }
        });

        btnXoaXpath.setText("Xóa");
        btnXoaXpath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaXpathActionPerformed(evt);
            }
        });

        btnThoatXpath.setText("Thoát");
        btnThoatXpath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatXpathActionPerformed(evt);
            }
        });

        btnCapNhatXpath.setText("Cập nhật");
        btnCapNhatXpath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCapNhatXpathActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabXpathLayout = new javax.swing.GroupLayout(tabXpath);
        tabXpath.setLayout(tabXpathLayout);
        tabXpathLayout.setHorizontalGroup(
            tabXpathLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabXpathLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabXpathLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(tabXpathLayout.createSequentialGroup()
                        .addComponent(btnThemXpath)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCapNhatXpath)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnXoaXpath)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnThoatXpath)))
                .addContainerGap())
        );

        tabXpathLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCapNhatXpath, btnThemXpath, btnThoatXpath, btnXoaXpath});

        tabXpathLayout.setVerticalGroup(
            tabXpathLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabXpathLayout.createSequentialGroup()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(tabXpathLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThemXpath)
                    .addComponent(btnXoaXpath)
                    .addComponent(btnThoatXpath)
                    .addComponent(btnCapNhatXpath))
                .addContainerGap())
        );

        tabPannel.addTab("Xpath", tabXpath);

        tabDatabase.setBackground(java.awt.Color.white);

        javax.swing.GroupLayout tabDatabaseLayout = new javax.swing.GroupLayout(tabDatabase);
        tabDatabase.setLayout(tabDatabaseLayout);
        tabDatabaseLayout.setHorizontalGroup(
            tabDatabaseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 577, Short.MAX_VALUE)
        );
        tabDatabaseLayout.setVerticalGroup(
            tabDatabaseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 344, Short.MAX_VALUE)
        );

        tabPannel.addTab("Database", tabDatabase);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(tabPannel))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabPannel, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnThemWebsiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemWebsiteActionPerformed
        Website website = new Website(null, true, 0, -1);
        GUI.ShowCenterScreen(website);
        website.setVisible(true);
        if (website.isReset && createJTableWebsite()) {
            tbWebsite.setRowSelectionInterval(tbWebsite.getRowCount() - 1, tbWebsite.getRowCount() - 1);
            tbWebsite.scrollRectToVisible(tbWebsite.getCellRect(tbWebsite.getRowCount() - 1, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnThemWebsiteActionPerformed

    private void btnThoatWebsiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatWebsiteActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnThoatWebsiteActionPerformed

    private void btnThemChuDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemChuDeActionPerformed
        Category category = new Category(null, true, 0, -1);
        GUI.ShowCenterScreen(category);
        category.setVisible(true);
        if (category.isReset && CreateJTablesubject()) {
            tbChuDe.setRowSelectionInterval(tbChuDe.getRowCount() - 1, tbChuDe.getRowCount() - 1);
            tbChuDe.scrollRectToVisible(tbChuDe.getCellRect(tbChuDe.getRowCount() - 1, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnThemChuDeActionPerformed

    private void btnXoaChuDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaChuDeActionPerformed
        // TODO add your handling code here:
        int row = tbChuDe.getSelectedRow();
        int ma = (int) tbChuDe.getValueAt(row, 0);
        int result = JOptionPane.showConfirmDialog(null,
                "Xóa chủ đề " + tbChuDe.getValueAt(row, 1) + "?", "Xóa chủ đề", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            ArrayList<TinTucDTO> listTin = TinTucDAO.SelectDanhSachTinTuc(-1, ma);
            if (ChuDeDAO.deleteChuDe(ma)) {
                JOptionPane.showMessageDialog(null, "Xóa Thành Công", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
                if (listTin != null) {
                    for (int i = 0; i < listTin.size(); i++) {
                        File f = new File("Image\\" + listTin.get(i).getMaTinTuc() + ".jpg");
                        if (f.exists()) {
                            f.delete();
                        }
                    }
                }
                if (CreateJTablesubject()) {
                    if (row != 0) {
                        row = row - 1;
                    }
                    tbChuDe.setRowSelectionInterval(row, row);
                    tbChuDe.scrollRectToVisible(tbChuDe.getCellRect(row, 0, true));
                }
                isReset = true;
            } else {
                JOptionPane.showMessageDialog(null, "Xóa Thất Bại", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_btnXoaChuDeActionPerformed

    private void btnThoatChuDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatChuDeActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnThoatChuDeActionPerformed

    private void btnXoaWebsiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaWebsiteActionPerformed
        int row = tbWebsite.getSelectedRow();
        int ma = (int) tbWebsite.getValueAt(row, 0);
        int result = JOptionPane.showConfirmDialog(null,
                "Xóa website " + tbWebsite.getValueAt(row, 1) + "?", "Xóa website", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            ArrayList<TinTucDTO> listTin = TinTucDAO.SelectDanhSachTinTuc(ma, -1);
            if (WebsiteDAO.DeleteWebsite(ma)) {
                JOptionPane.showMessageDialog(null, "Xóa Thành Công", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
                if (listTin != null) {
                    for (int i = 0; i < listTin.size(); i++) {
                        File f = new File("Image\\" + listTin.get(i).getMaTinTuc() + ".jpg");
                        if (f.exists()) {
                            f.delete();
                        }
                    }
                }
                if (createJTableWebsite()) {
                    if (row != 0) {
                        row = row - 1;
                    }
                    tbWebsite.setRowSelectionInterval(row, row);
                    tbWebsite.scrollRectToVisible(tbWebsite.getCellRect(row, 0, true));
                }
                isReset = true;
            } else {
                JOptionPane.showMessageDialog(null, "Xóa Thất Bại", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_btnXoaWebsiteActionPerformed

    private void btnCapNhatChuDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapNhatChuDeActionPerformed
        int row = tbChuDe.getSelectedRow();
        int ma = (int) tbChuDe.getValueAt(row, 0);
        Category category = new Category(null, true, 1, ma);
        GUI.ShowCenterScreen(category);
        category.setVisible(true);
        if (category.isReset && CreateJTablesubject()) {
            tbChuDe.setRowSelectionInterval(row, row);
            tbChuDe.scrollRectToVisible(tbChuDe.getCellRect(row, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnCapNhatChuDeActionPerformed

    private void btnThemXpathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemXpathActionPerformed
        Xpath xpath = new Xpath(null, true, 0, -1);
        GUI.ShowCenterScreen(xpath);
        xpath.setVisible(true);
        if (xpath.isReset && createJTableWebsite()) {
            tbXpath.setRowSelectionInterval(tbXpath.getRowCount() - 1, tbXpath.getRowCount() - 1);
            tbXpath.scrollRectToVisible(tbXpath.getCellRect(tbXpath.getRowCount() - 1, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnThemXpathActionPerformed

    private void btnXoaXpathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaXpathActionPerformed
        int row = tbXpath.getSelectedRow();
        int ma = (int) tbXpath.getValueAt(row, 0);
        int result = JOptionPane.showConfirmDialog(null,
                "Xóa xpath " + tbXpath.getValueAt(row, 1) + "?", "Thông tin", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            if (XpathDAO.deleteXpath(ma)) {
                JOptionPane.showMessageDialog(null, "Xóa Thành Công", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
                if (CreateJtableXpath()) {
                    if (row != 0) {
                        row = row - 1;
                    }
                    tbXpath.setRowSelectionInterval(row, row);
                    tbXpath.scrollRectToVisible(tbXpath.getCellRect(row, 0, true));
                }
                isReset = true;
            } else {
                JOptionPane.showMessageDialog(null, "Xóa Thất Bại", "Thông Tin", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_btnXoaXpathActionPerformed

    private void btnThoatXpathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatXpathActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnThoatXpathActionPerformed

    private void btnCapNhatXpathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapNhatXpathActionPerformed
        int row = tbXpath.getSelectedRow();
        int ma = (int) tbXpath.getValueAt(row, 0);
        Xpath xpath = new Xpath(null, true, 1, ma);
        GUI.ShowCenterScreen(xpath);
        xpath.setVisible(true);
        if (xpath.isReset && CreateJtableXpath()) {
            tbXpath.setRowSelectionInterval(row, row);
            tbXpath.scrollRectToVisible(tbXpath.getCellRect(row, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnCapNhatXpathActionPerformed

    private void btnCapNhatWebsiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCapNhatWebsiteActionPerformed
        int row = tbWebsite.getSelectedRow();
        int ma = (int) tbWebsite.getValueAt(row, 0);
        Website website = new Website(null, true, 1, ma);
        GUI.ShowCenterScreen(website);
        website.setVisible(true);
        if (website.isReset && createJTableWebsite()) {
            tbWebsite.setRowSelectionInterval(row, row);
            tbWebsite.scrollRectToVisible(tbWebsite.getCellRect(row, 0, true));
            isReset = true;
        }
    }//GEN-LAST:event_btnCapNhatWebsiteActionPerformed

    private void tabPannelStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabPannelStateChanged
        if(tabPannel.getSelectedIndex() ==3){
            ConnectionDatabase con = new ConnectionDatabase(null, true, false);
            GUI.ShowCenterScreen(con);
            con.setVisible(true);
            
            tabPannel.setSelectedIndex(0);
            if(con.isreset){
                createJTableWebsite();
            }
        }
    }//GEN-LAST:event_tabPannelStateChanged

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
       
    }//GEN-LAST:event_formWindowActivated

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Manager dialog = new Manager(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel TabChuDe;
    private javax.swing.JButton btnCapNhatChuDe;
    private javax.swing.JButton btnCapNhatWebsite;
    private javax.swing.JButton btnCapNhatXpath;
    private javax.swing.JButton btnThemChuDe;
    private javax.swing.JButton btnThemWebsite;
    private javax.swing.JButton btnThemXpath;
    private javax.swing.JButton btnThoatChuDe;
    private javax.swing.JButton btnThoatWebsite;
    private javax.swing.JButton btnThoatXpath;
    private javax.swing.JButton btnXoaChuDe;
    private javax.swing.JButton btnXoaWebsite;
    private javax.swing.JButton btnXoaXpath;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel tabDatabase;
    private javax.swing.JTabbedPane tabPannel;
    private javax.swing.JPanel tabWebsite;
    private javax.swing.JPanel tabXpath;
    private javax.swing.JTable tbChuDe;
    private javax.swing.JTable tbWebsite;
    private javax.swing.JTable tbXpath;
    // End of variables declaration//GEN-END:variables
}
